package com.spring.springmvc.表白墙;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

//点击提交保存数据
@RequestMapping("message")
@RestController
public class messagewall {
//    List<Message> list = new ArrayList<>();

    @Autowired
    MessageWallService messageWallService;
    @RequestMapping("submit")

    public boolean submit(Message message){
         if(!StringUtils.hasLength(message.getFrom())||
              !StringUtils.hasLength(message.getTo())||
                 !StringUtils.hasLength(message.getSay())){
            return false;
        }
//        list.add(message);

        int n =  messageWallService.insertMessage(message);
         if(n>0){
             return true;
         }else {
             return false;
         }
    }

    @RequestMapping("getlist")
    public List<Message> getList(){
//        return list;
        return messageWallService.getMessages();
    }
}
